package itdep.domain.security;

import ga.security.Secured;
import itdep.domain.CodedEntity;
import itdep.domain.TranslationType;

import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * @author Ivan Khalopik
 * @version $Revision: 34 $ $Date: 2010-06-20 09:57:55 +0000 (Sun, 20 Jun 2010) $
 */
@Entity
@Table(name = "PERMISSION")
public class Permission extends CodedEntity implements Secured {
	private static final String PERMISSION_PREFIX = "PERMISSION_";

	@ManyToMany(mappedBy = "permissions")
	private Set<Role> roles = new HashSet<Role>();

	public Permission() {
		super("permission", TranslationType.STANDARD);
	}

	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	@Override
	public String getAuthority() {
		return PERMISSION_PREFIX + getCode().toUpperCase();
	}

	@Override
	public Collection<? extends Secured> getChildrenSecured() {
		return null;
	}
}